package com.xj.demo.unknow;

import java.util.HashSet;
import java.util.Set;

public class HashCodeTest {
    public static void main(String[] args) {
        A a = new A(1);
        A b = new A(1);
        System.out.println(a.equals(b));
        Set<A> set = new HashSet<>();
        set.add(a);
        set.add(b);
        System.out.println(set);
    }
}
class A{
    int a;
    public A(int a){
        this.a = a;
    }
    //重写equals
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        A other = (A) obj;
        return a == other.a;
    }
    //重写toString
    @Override
    public String toString() {
        return "A [a=" + a + "]";
    }
}
